function [a,P] = PassOrDribble(P,S,mode)
% game parameters
global num_players_r;
global num_players_b;

if(P{2}=='r')
    num_players = num_players_r;
    num_opponents = num_players_b;
else
    num_players = num_players_b;
    num_opponents = num_players_r;
end

P_X=P{1}(1);
P_Y=P{1}(2);
P_color=P{2};

close = 0;

for l=2:numel(S) % check opponents
    if(S{l}{2} ~= P_color)
        Sl=S{l};
        Sl_X=Sl{1}(1);
        Sl_Y=Sl{1}(2);

        if(abs(Sl_X-P_X) + abs(Sl_Y-P_Y) <16 &&  abs(Sl_X-(-58)) < abs(P_X-(-58)) )    % close - do not dribble - dangerous
            close=1;

            k = round(rand_num(0.5,num_players+0.5)); % choose a random team-mate to pass to
            [a,P] = PassBall(P,S,mode,k);
            SaveMemory(P,true,1+k,0);
            break;
        end
    end
end

if(~close) % just dribble
    [a, P] = Dribble(P);
    SaveMemory(P,false,1,0);
end

end